
***************************************************
* Figure B.4
***************************************************


use "$workdata/baseline", clear /* see $data_do/baseline.do */

capture drop apprent
g apprent=y==521
bysort pnr: egen apprent_tot=max(apprent)
g wage_appr_mis=wage if apprent_tot==0
g wage_appr_0=wage
replace wage_appr_0=0 if apprent_tot==1

g wage_appr_0_2=wage
replace wage_appr_0_2=0 if apprent==1

collapse wage wage_appr_mis wage_appr_0 apprent_tot wage_appr_0_2 (sum) e if age_q>=21 & age_q<29 , by(age_q)

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
g d=age_q>=25
g age_q0=age_q-25
g age_q0_2= age_q0^2
g age_q0_3= age_q0^3
g dXage_q0=d*age_q0
g dXage_q0_2=d*age_q0_2
g dXage_q0_3=d*age_q0_3

sum apprent_tot if resp==1 [aw=e]

reg wage d age_q0 age_q0_2 dXage_q0 dXage_q0_2 if resp==0 [aw=e]
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
local b_wage=`beta_d'
predict yhat
reg wage_appr_mis d age_q0 age_q0_2 dXage_q0 dXage_q0_2 if resp==0 [aw=e]
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
local b_mis=`beta_d'
predict yhat_mis
reg wage_appr_0 d age_q0 age_q0_2 dXage_q0 dXage_q0_2 if resp==0 [aw=e]
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
local b_0=`beta_d'
predict yhat0
reg wage_appr_0_2 d age_q0 age_q0_2 dXage_q0 dXage_q0_2 if resp==0 [aw=e]
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
local b_0_2=`beta_d'
predict yhat0_2


twoway ///
(connect wage age_q if age_q==0, msymbol(O) mlcolor(gs10) mfcolor(gs16) lcolor(gs2) lpattern(solid) lwidth(medthick) msize(medium)) ///
(connect wage_appr_mis age_q if age_q==0, msymbol(s) mlcolor(gs8) mfcolor(gs16) lcolor(gs1) lpattern(shortdash) lwidth(medium) msize(medium)) ///
(connect wage_appr_0_2 age_q if age_q==0, msymbol(x) mcolor(gs4) lcolor(gs12) lpattern(dash) lwidth(medium) msize(medium)) ///
(scatter wage age_q, msymbol(O) mlcolor(gs8) mfcolor(gs16) msize(medium)) ///
(scatter wage_appr_mis age_q, msymbol(s) mlcolor(gs8) mfcolor(gs16) msize(medium)) ///
(scatter wage_appr_0_2 age_q if age_q>=24.8, msymbol(x) mcolor(gs4) msize(medium) ) ///
(line yhat age_q if age_q<25, lcolor(gs2) lpattern(solid) lwidth(medthick))      ///
(line yhat age_q if age_q>=25, lcolor(gs2) lpattern(solid) lwidth(medthick))      ///
(line yhat_mis age_q if age_q<25, lcolor(gs1) lpattern(shortdash) lwidth(medium)) ///
(line yhat_mis age_q if age_q>=25, lcolor(gs1) lpattern(shortdash) lwidth(medium)) ///
(line yhat0_2 age_q if age_q<25, lcolor(gs12) lpattern(dash) lwidth(medium)) ///
(line yhat0_2 age_q if age_q>=25, lcolor(gs12) lpattern(dash) lwidth(medium)) ///
, xline(24.95833) scheme(s1mono) ytitle("Employment" , height(5)) xtitle("Age in months" , height(5)) ///
xlabel(21(1)29) ///
legend(order(1 "Baseline (effect size: `b_wage' pp)" 2 "Excl. those joining Adult Apprent. (`b_mis' pp)" 3 "Treating Adult Apprent. as non-employment (`b_0_2' pp)" /*4 "AAP particpants=0 (`b_0' pp)"*/) symxsize(*0.8) cols(1) size(medsmall)) ///
name(figB4, replace) 

graph save figB4  $figures/figB4, replace
graph export $figures/figB4.pdf, name(figB4) replace
graph export $figures/figB4.png, name(figB4) replace


***************************************************
* end: Figure B.4
***************************************************
